﻿using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

using System.Data;
using System.Text;
using Maticsoft.DBUtility;
using Utils;
using System.Collections.Specialized;
using Maticsoft.Model;


public partial class shopcart_pay : FBasePage
{
    // Fields
    public string Amt;

    public string money;
    public Maticsoft.BLL.Order orderbll = new Maticsoft.BLL.Order();
    public string orderid;
    protected Order ordermodel = new Order();
    public string pcat;
    public string pd_FrpId;
    public string Pdesc;
    public string Pid;
    public string service;
    public Maticsoft.BLL.Team teambll = new Maticsoft.BLL.Team();
    public Maticsoft.BLL.UserInfo userbll = new Maticsoft.BLL.UserInfo();

    // Methods
    public void GetMoney(string orderid)
    {
        decimal num;
        Team model = new Team();
        this.ordermodel = this.orderbll.GetModel(Convert.ToInt32(orderid));
        model = this.teambll.GetModel(Convert.ToInt32(this.ordermodel.Team_id));
        UserInfo info2 = new Maticsoft.BLL.UserInfo().GetModel(this.ordermodel.User_id);
        this.service = this.ordermodel.Service;
        if (info2.Money < this.ordermodel.Origin)
        {
            num = this.ordermodel.Origin - info2.Money;
            this.money = num.ToString();
            num = this.ordermodel.Origin - info2.Money;
            this.Amt = num.ToString();
        }
        else
        {
            num = info2.Money - (info2.Money - this.ordermodel.Origin);
            this.money = num.ToString();
            this.Amt = (info2.Money - (info2.Money - this.ordermodel.Origin)).ToString();
        }
        this.Pid = base.ASSystem.abbreviation + "商品-订单编号" + this.ordermodel.Id;
    }

    protected override void OnLoad(EventArgs e)
    {
        base.OnLoad(e);
        if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
        {
            base.Response.Redirect("/account/Login.aspx");
        }
        if (base.Request["orderid"] != null)
        {
            this.GetMoney(base.Request["orderid"].ToString());
            this.orderid = base.Request["orderid"].ToString();
        }
        else
        {
            base.Response.Redirect("/account/Login.aspx");
        }
        if (base.Request["pd_FrpId"] != null)
        {
            this.pd_FrpId = base.Request["pd_FrpId"].ToString();
        }
        if (base.Request.Form["pay"] == "使用账户余额支付")
        {
            if (!(this.Page.User.Identity.IsAuthenticated && !(this.Page.User.Identity.Name == "")))
            {
                base.Response.Redirect("/account/Login.aspx");
            }
            if (Maticsoft.BLL.Order.isjudge(base.AsUser.Money, this.ordermodel.Origin))
            {
                Maticsoft.BLL.Order.Updateorder(this.ordermodel.Pay_id, "0", "credit");
            }
            base.Response.Redirect("../order/success.aspx?id=" + this.orderbll.GetModel(Convert.ToInt32(base.Request["orderid"].ToString())).Pay_id);
            base.Response.End();
        }
    }

}